<template>
  <view class="rollnumber">
    <view class="dotask" v-if="doTask == 1">
      <text>浏览当前页面</text>
      <u-count-to ref="uCountTo" class='number' color='#fff' :start-val="requiredTime" :end-val="0"
        :duration='requiredTime*1000' :use-easing="false" :font-size='26' @end='end' :autoplay='false'></u-count-to>
      <text> 秒，完成任务</text>
    </view>
    <view class="finish" v-if="doTask == 0">任务已完成，返回<text class="under-line" @click="skipPage">参与活动</text></view>
  </view>
</template>

<script>
  import api from '@/api/api';
  export default {
    data() {
      return {
        stop: false
      }
    },
    props: {
      doTask: {
        typeof: Number
      },
      requiredTime: {
        typeof: Number
      }
    },
    mounted() {
      setTimeout(() => {
        if (this.doTask) {
          this.$refs.uCountTo.start();
        }
      }, 2000)

    },
    destroyed() {
      if (!this.stop && this.doTask) {
        this.paused()
      }
    },
    methods: {
      paused() {
        this.$refs.uCountTo.stop();
      },
      end() {
        this.stop = true
        this.$parent.changeTaskStatus()
      },
      skipPage() {
        let url;
        if (api.environment == 'formal') {
          url = '/pages/item/search?cateCode=16730&title=不凡甄选&navId=9398'
        } else if (api.environment == 'trial') {
          url = '/pages/item/search?cateCode=7962&title=不凡甄选&navId=4503'
        }
        if (!!url) {
          uni.navigateTo({
            url: url
          })
        }
      }
    }
  }
</script>

<style lang="scss">
  .rollnumber {
    background: #4D4D4D;
    text-align: center;
    padding: 20rpx 10px;

    view {
      font-size: 26rpx;
      color: #fff;

      .number {
        margin: 0 2rpx;
      }

      .under-line {
        border-bottom: 1px solid #fff;
      }
    }
  }
</style>
